Computer Science Engineering (CSE) Exam  >  Computer Science Engineering (CSE) Questions  >  What is the output of the following program s... Start Learning for Free
What is the output of the following program segment?
int max (int x, int y, int m)
{
if (x > 5)
m = x;
else m = y;
}
int main()
{
int i = 20, j = 5, k = 0;
max (i, j, k);
printf("%d",k);
}
    Correct answer is '0'. Can you explain this answer?
    Most Upvoted Answer
    What is the output of the following program segment?int max (int x, in...
    Understanding the Program Segment
    The provided program segment consists of a function `max` and the `main` function. Let's analyze how it works.
    Function Definition
    - The `max` function takes three integer parameters: `x`, `y`, and `m`.
    - Inside the function, there is a conditional check: if `x` is greater than 5, it assigns `m` the value of `x`. Otherwise, it assigns `m` the value of `y`.
    Function Call in Main
    - In the `main` function, three integers are declared: `i = 20`, `j = 5`, and `k = 0`.
    - The `max` function is called with `i`, `j`, and `k` as arguments.
    Key Points of Execution
    - When `max(i, j, k)` is invoked, the values passed are `x = 20`, `y = 5`, and `m = 0`.
    - Since `20` (value of `x`) is greater than `5`, `m` is assigned the value of `20` inside the function.
    - However, this change to `m` does not affect `k` in `main` because C passes parameters by value, not by reference.
    Final Output
    - The value of `k` remains unchanged at `0`, as the modification to `m` in the `max` function does not reflect back to `k`.
    - The program outputs `0` when `printf` is called.
    Conclusion
    - The output of the program is `0` because the variable `k` is not modified in the `main` function, despite the `max` function's operations.
    Free Test
    Community Answer
    What is the output of the following program segment?int max (int x, in...
    Since the above program segment is implemented by the call by value method, so the value of k remains unaltered and equals zero.
    Explore Courses for Computer Science Engineering (CSE) exam

    Top Courses for Computer Science Engineering (CSE)

    What is the output of the following program segment?int max (int x, int y, int m){if (x > 5)m = x;else m = y;}int main(){int i = 20, j = 5, k = 0;max (i, j, k);printf("%d",k);}Correct answer is '0'. Can you explain this answer?
    Question Description
    What is the output of the following program segment?int max (int x, int y, int m){if (x > 5)m = x;else m = y;}int main(){int i = 20, j = 5, k = 0;max (i, j, k);printf("%d",k);}Correct answer is '0'. Can you explain this answer? for Computer Science Engineering (CSE) 2025 is part of Computer Science Engineering (CSE) preparation. The Question and answers have been prepared according to the Computer Science Engineering (CSE) exam syllabus. Information about What is the output of the following program segment?int max (int x, int y, int m){if (x > 5)m = x;else m = y;}int main(){int i = 20, j = 5, k = 0;max (i, j, k);printf("%d",k);}Correct answer is '0'. Can you explain this answer? covers all topics & solutions for Computer Science Engineering (CSE) 2025 Exam. Find important definitions, questions, meanings, examples, exercises and tests below for What is the output of the following program segment?int max (int x, int y, int m){if (x > 5)m = x;else m = y;}int main(){int i = 20, j = 5, k = 0;max (i, j, k);printf("%d",k);}Correct answer is '0'. Can you explain this answer?.
    Solutions for What is the output of the following program segment?int max (int x, int y, int m){if (x > 5)m = x;else m = y;}int main(){int i = 20, j = 5, k = 0;max (i, j, k);printf("%d",k);}Correct answer is '0'. Can you explain this answer? in English & in Hindi are available as part of our courses for Computer Science Engineering (CSE). Download more important topics, notes, lectures and mock test series for Computer Science Engineering (CSE) Exam by signing up for free.
    Here you can find the meaning of What is the output of the following program segment?int max (int x, int y, int m){if (x > 5)m = x;else m = y;}int main(){int i = 20, j = 5, k = 0;max (i, j, k);printf("%d",k);}Correct answer is '0'. Can you explain this answer? defined & explained in the simplest way possible. Besides giving the explanation of What is the output of the following program segment?int max (int x, int y, int m){if (x > 5)m = x;else m = y;}int main(){int i = 20, j = 5, k = 0;max (i, j, k);printf("%d",k);}Correct answer is '0'. Can you explain this answer?, a detailed solution for What is the output of the following program segment?int max (int x, int y, int m){if (x > 5)m = x;else m = y;}int main(){int i = 20, j = 5, k = 0;max (i, j, k);printf("%d",k);}Correct answer is '0'. Can you explain this answer? has been provided alongside types of What is the output of the following program segment?int max (int x, int y, int m){if (x > 5)m = x;else m = y;}int main(){int i = 20, j = 5, k = 0;max (i, j, k);printf("%d",k);}Correct answer is '0'. Can you explain this answer? theory, EduRev gives you an ample number of questions to practice What is the output of the following program segment?int max (int x, int y, int m){if (x > 5)m = x;else m = y;}int main(){int i = 20, j = 5, k = 0;max (i, j, k);printf("%d",k);}Correct answer is '0'. Can you explain this answer? tests, examples and also practice Computer Science Engineering (CSE) tests.
    Explore Courses for Computer Science Engineering (CSE) exam

    Top Courses for Computer Science Engineering (CSE)

    Explore Courses
    Signup for Free!
    Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
    10M+ students study on EduRev